package service

import (
	"context"
	"fmt"
	__ "server/basic/proto"
	"server/handler/models"
)

// server is used to implement helloworld.GreeterServer.
type Server struct {
	__.UnimplementedUserServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) Register(_ context.Context, in *__.RegisterReq) (*__.RegisterResp, error) {
	var user models.User
	user.Username = in.Username
	user.Password = in.Password
	if err := user.CreateUser(); err != nil {
		return nil, fmt.Errorf("用户注册失败")
	}
	return &__.RegisterResp{
		Id: int64(user.Id),
	}, nil
}
